﻿using System;
using System.Collections.Generic;
using System.Text;

public class PlayersService
{
    private const int k_PlayerVsPlayerMode = 1;
    private const char k_X = 'X';
    private const char k_O = 'O';
    private readonly List<Player> r_ListOfPlayers = null;
    private bool IsTwoUserPlayers = false;

    public int NumOfPlayers
    {
        get { return r_ListOfPlayers.Count; }
    }

    public PlayersService(bool i_IsTwoUserPlayers)
    {
        IsTwoUserPlayers = i_IsTwoUserPlayers;
        r_ListOfPlayers = new List<Player>();

        Player FirstPlayer = new Player(Player.ePlayerType.User, k_X);
        r_ListOfPlayers.Add(FirstPlayer);

        Player SecondPlayer = null;

        if (i_IsTwoUserPlayers == true)
        {
            SecondPlayer = new Player(Player.ePlayerType.User, k_O);
        }
        else
        {
            SecondPlayer = new Player(Player.ePlayerType.Pc, k_O);
        }

        r_ListOfPlayers.Add(SecondPlayer);
    }

    public Player GetPlayerByIndex(int i_PlayerIndex)
    {
        return r_ListOfPlayers[i_PlayerIndex];
    }

    public void UpdateWinnerScore(int i_PlayerIndex)
    {
        r_ListOfPlayers[i_PlayerIndex].Score += 1;
    }

    public int GetPlayerScoreByIndex(int i_PlayerIndex)
    {
        return r_ListOfPlayers[i_PlayerIndex].Score;
    }

    public void ResetPlayersScore()
    {
        foreach (Player player in r_ListOfPlayers)
        {
            player.Score = 0;
        }
    }
}
